﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Common;

namespace AOP
{
    public class AOPLogin:ActionFilterAttribute
    {
        //在ActionFilterAttribute基类中有个抽象方当
        //public abstract void OnActionExecuting(ActionExecutingContext filterContext);
        //在ActionFilterAttribute基类中有个抽象方当
        //public abstract void OnActionExecuting(ActionExecutingContext filterContext);
        //顾名思义就是指当要执行一个Action之前要做啥工作.在CheckLoginAttribute继承主类后,要将该OnActionExecuting(..)方法重写如:
        //public override void OnActionExecuting(ActionExecutingContext filterContext)
        //{} // end Action
        //这样的话,我们就可以将我们想做的处理写在该方法里头.如:
        //public override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
            // 如果用户没有登陆
              //CookieDESC cookie=new CookieDESC();
                //if(!cookie.Online)
                //{
                //    string url= filterContext.HttpContext.Request.Url.AbsolutePath;
                //    filterContext.Result = new RedirectResult("/User/Login?ReturnUrl="+url,true);
                //}
        //}

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            int UserID;
            int.TryParse(CommonCookie.GetCookie("UserID"),out UserID);
            if(CommonCookie.GetCookie("UserID")==null)
            {
                filterContext.HttpContext.Response.Redirect("/Sofa/Index");
            }
            base.OnActionExecuting(filterContext);
        }
    }
}
